home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / DEC16OUT < prev    next >
Encoding:
Text File  |  1985-12-22  |  1.9 KB  |  75 lines

  1. ;-------------------------dec16out routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 61
  4. ;
  5. ; NAME DEC16OUT
  6. ; ROUTINE FOR Conversion from 16-bit Binary to ASCII decimal
  7. ;
  8. ; FUNCTION: This routine accepts a 16-bit binary number in the DX register
  9. ; and converts it to ASCII decimal form which is sent to the std input
  10. ; device.
  11. ;
  12. ; INPUT: Upon entry an 16-bit binary number is in DX
  13. ; OUTPUT: A string of ASCII digits representing a decimal number is
  14. ; stored in a buffer called TBUFF and then sent out through the std output
  15. ; device.
  16. ; REGISTERS USED:  No registers are modified.  DX is used for input.
  17. ; SEGMENTS REFERENCED:  DATAS is a data segment which contains TBUFF.
  18. ; ROUTINES CALLED:  STDOUT
  19. ; SPECIAL NOTES: None
  20. ;
  21. ; ROUTINE TO CONVERT FROM INTERNAL 16-BIT BINARY TO ASCII DECIMAL.
  22. ;
  23. dec16out    proc    far
  24. ;
  25.     push    ds        ; save registers
  26.     push    di
  27.     push    dx
  28.     push    cx
  29.     push    ax
  30. ;
  31.     mov    ax,datas    ; point to the data segment
  32.     mov    ds,ax
  33. ;
  34. ; binary number is in DX
  35. ;
  36. ; Put the digits in a buffer
  37. ;
  38.     mov    cx,0        ; initialize a counter
  39.     lea    di, tbuff     ; point to a buffer
  40. ;
  41. dec16out1:
  42.     push    cx        ; save the count
  43.     mov    ax,dx        ; AX has the numerator
  44.     mov    dx,0        ; clear upper half
  45.     mov    cx,10        ; divisor of 10
  46.     div    cx        ; divide
  47.     xchg    ax,dx        ; get quotient
  48. ;
  49.     add    al,30h        ; increase to ASCII
  50.     mov    [di],al        ; put in tbuff
  51.     inc    di        ; point to next byte
  52. ;
  53.     pop    cx        ; restore count
  54.     inc    cx        ; count the digit
  55.     cmp    dx,0        ; done ?
  56.     jnz    dec16out1
  57. ;
  58. ; dump tbuff out
  59. ;
  60. dec16out2
  61.     dec    di        ; back up through the tbuff
  62.     mov    al,[di]        ; get the byte from the tbuff
  63.     call    stdout        ; send it
  64.     loop    dec16out2
  65. ;
  66.     pop    ax        ; restore registers
  67.     pop    cx
  68.     pop    dx
  69.     pop    di
  70.     pop    ds
  71.     ret            ; return
  72. ;
  73. dec16out    endp
  74. ;-------------------------dec16out routine ends---------------------------+
  75.